package com.itheima.homework.assignment;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * 某公司人事举办了这样一个活动,凡是入职6周年的员工,赠送一个精美小礼品,
 * 于是员工纷纷去计算了自己的入职年限,请设计程序,帮同事们计算出入职年限.
 */
public class Test02 {
    public static void main(String[] args) throws ParseException {
        //1. 接受键盘录入的入职日期字符串
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您的入职日期（以'xxxx年xx月xx日'的格式）：");
        String enroll = sc.next();

        //2. 将日期字符串转换为日期对象，方便获取毫秒值
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        Date enrollDate = sdf.parse(enroll);

        //3. 获取入职日期的毫秒值
        long enrollTime = enrollDate.getTime();

        //4. 获取当前系统的毫秒值
        Calendar now = Calendar.getInstance();
        long timeInMillis = now.getTimeInMillis();

        //5. 计算时间差
        long time = timeInMillis - enrollTime;

        //6.将单位换算成天
        long day = time / 1000 / 60 / 60 / 24;
        int year = (int) (day / 365);

        ////7.将天换算成年,并打印
        System.out.println("您已经入职" + year + "年了～");
    }
}
